function removeFile(count, divId) {
    var parentElm = document.getElementById(divId);
    parentElm.deleteRow($('#row' + count).index());
}

function addFile(divId, docCategory, rowCount) {
    $('#' + divId).show();
    var parentElm = $('#' + divId);
    var newRow = $("<tr id='row" + rowCount + "'/>");
    var category = $('<td />');
    var optionList = '<select name="documentCategory">';
    $.each(docCategory, function(key, value) {
        optionList += '<option value="' + key + '">' + value + '</option>';
    });
    optionList += '</select>';
    category.append(optionList);
    newRow.append(category);

    var fileTD = $('<td/>');

    var file = document.createElement('input');
    file.setAttribute('name', 'files');
    file.setAttribute('type', 'file');
    fileTD.html(file);

    newRow.append(fileTD);

    var deleteButtonTD = $('<td/>');

    var btn = document.createElement('input');
    btn.setAttribute('type', 'button');
    btn.setAttribute('value', 'Delete');

    btn.onclick = function() {
        removeFile(rowCount, divId)
    };

    deleteButtonTD.html(btn);
    newRow.append(deleteButtonTD);

    rowCount++;

    parentElm.append(newRow);
}

function openDocument(docId) {
    var url = '${"downloadFile.do?documentId=' + docId + '"}';
    $.get(url, function (data) {
    });
}
